import {fetchCategory,fetchSlide} from '@/api/home.js'

export default{
    namespaced:true,
    state:{
        categories:[],
        slides:[],
        currentLesson:-1
    },
    mutations:{
        setCategories(state,payload){
            state.categories = payload;
        },
        setSlides(state,payload){
            state.slides = payload
        },
        setCurrentLesson(state,value){
            state.currentLesson =value
        }
    },
    actions:{
        //fetchCategory是ajax请求方法 异步的 所以写在actions
        // 通过this.$store.dispatch('actions中的方法') 再到actions中通过commit 通知Mutation执行
        async setCategories({commit}){
           let categories =  await fetchCategory();
           commit('setCategories',categories)
        },
        async setSlides({commit}){
            let slides = await fetchSlide()
            commit('setSlides',slides)
        }
    }
}